//
//  DetailTableViewCell.m
//  Contractor
//
//  Created by 金鑫 on 16/5/5.
//  Copyright © 2016年 star j. All rights reserved.
//

#import "DetailTableViewCell.h"
#import "CONST.h"

@implementation DetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //标题
        self.titleLabel = [self creatlabel] ;
        //数据
        self.dataLabel = [self creatlabel] ;
        
        //第一个图片
        UIImageView *firstImage = [[UIImageView alloc] init] ;
        [self.contentView addSubview:firstImage] ;
        self.firstView = firstImage ;
        
    }
    return self ;
}

//创建label
- (UILabel *)creatlabel
{
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:14.0f] ;
    label.backgroundColor = [UIColor clearColor] ;
    [self.contentView addSubview:label] ;
    return label ;
}

//初始化cell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    
    static NSString *identifier = @"cellID" ;
    DetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier] ;
    if (!cell) {
        cell = [[DetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;
    }
    return cell ;
}

- (void)configTitle:(NSString *)title configImage:(UIImage *)image withData:(NSString *)dataStr
{
    self.titleLabel.text = title ;
    self.dataLabel.text = dataStr ;
    [self.firstView setImage:image] ;
    [self setSubviewFrame] ;
}

- (void)setSubviewFrame
{
    self.firstView.frame = CGRectMake(10, 12, 26, 26) ;
    
    CGSize titlelgth = [self lengthwithLabel:self.titleLabel withsize:14.0f] ;
    self.titleLabel.frame = CGRectMake(50, 17, titlelgth.width, 16.0f) ;
    
   // CGSize datalgth = [self lengthwithLabel:self.dataLabel withsize:14.0f] ;
    
    
    self.dataLabel.numberOfLines = 0 ;
    self.dataLabel.textAlignment = NSTextAlignmentRight ;
    self.dataLabel.frame = CGRectMake(_titleLabel.frame.origin.x + _titleLabel.frame.size.width + 10, 0, __kScreenWidth - (_titleLabel.frame.origin.x + _titleLabel.frame.size.width + 20), 50.0f) ;
}

- (CGSize)lengthwithLabel:(UILabel *)lable withsize:(CGFloat) size
{
    NSDictionary *attribute1 = @{NSFontAttributeName: [UIFont fontWithName:@"AvenirLTStd-Light" size:size]};
    CGSize DescSize = [lable.text boundingRectWithSize:CGSizeMake(MAXFLOAT, size) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute1 context:nil].size;
    return DescSize ;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
